#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=100000;

int main() {
	freopen("a.in", "r", stdin);
	freopen("a_check.out", "w", stdout);

	static int s[maxn+1];
	int n;
	scanf("%d", &n);
	for (int i=1; i<=maxn; i++) {
		scanf("%d", s+i);
	}
	
	long long ans=0;
	for (int i=1; i<=n; i++) {
		for (int j=i+1; j<=n; j++) {
			for (int x=1; x<=n; x++) {
				if (x!=i && x!=j) {
					for (int y=x+1; y<=n; y++) {
						if (y!=i && y!=j) {
							if (s[i]<s[j] && s[x]>s[y]) {
								ans++;
							}
						}
					}
				}
			}
		}
	}
	printf("%lld", ans);

	fclose(stdin);
	fclose(stdout);
	return 0;
}
